<?php
namespace app\admin;

use think\exception\HttpResponseException;
use think\facade\Db;
use app\BaseController;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Session;
use think\facade\Request;
use think\Response;

/**
 * 后台公用基础控制器
 * Class AdminBase
 * @package app\common\controller
 */
class AdminBase extends BaseController
{
    protected function initialize()
    {

        parent::initialize();

        if (!Session::has('admin_id')) {
            if($this->request->isAjax()){
                $result = [
                    'code' => 3,
                    'msg' => "登录已过期",
                    'url' => "/admin/index",
                ];
                return  json($result);
            }
            $this->redirect(url('admin/login/index'));
        }
    }
    /**
     * 返回layui需要的json格式
     */
    public function layui_json( $data = array(), $count = 0, $code = 0,$msg = "操作成功")
    {
        $list = ['code' => $code, 'data' => $data, 'count' => $count, 'msg' => $msg];
        return json($list,$code);
    }



}